<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 基础表格
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
 
                    template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button>
                        <el-button
                            type="text"
                            icon="el-icon-delete"
                            class="red"
                            @click="handleDelete( scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="客户编号">
                    <el-input v-model="partsData.CustomersCno"></el-input>
                </el-form-item>
				<el-form-item label="客户名">
                    <el-input v-model="partsData.CustomersCname"></el-input>
                </el-form-item>
       <el-form-item label="修理项目">
                    <el-input v-model="partsData.CustomersCbesom"></el-input>
                </el-form-item>
              <el-form-item label="电话">
                <el-input v-model="partsData.CustomersPhonenum"></el-input>
              </el-form-item>
        </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { customerdelete,fetchgetcustomer } from '../../api/index';
import { fetchupdatecustomer } from '../../api/index';
export default {
    name: 'basetable',
    data() {
        return {

            tableData: [],
            tempcustomerData:{},
            multipleSelection: [],
            partsData: {},
            delList: [],
            query: {},
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getData();
    },
    methods: {
        getData() {
          fetchgetcustomer().then(res =>{console.info(res)
            this.tableData=res.data.value
            })
        },
        handleDelete(row) {
          this.tempcustomerData = row
          customerdelete(this.tempcustomerData).then(res=>{console.info(res)
                console.log(this.tempcustomerData)
                console.log(res)
                window.location.reload()
          })
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.partsData = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
          this.editVisible = false;
          this.$message.success(`修改第 ${this.idx + 1} 行成功`);
          fetchupdatecustomer(this.partsData).then(res =>{console.info(res)
            console.log(this.partsData)
            console.log(res)
          })
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
